<?php

namespace app\admin\model\spell;

use app\common\library\Sms;
use think\Model;


class Back extends Model
{





    // 表名
    protected $name = 'spell_back';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];


    /**
     * 订单回购
     */
    public static function buyBackInfo($order)
    {
        $pingorderbackpercent = \think\config::get("site.pingorderbackpercent");
        $backPercent = bcadd(100,$pingorderbackpercent,2);
        $backPrice = bcmul($order["payPrice"],bcmul($backPercent,0.01,2),2);
        $data = array(
            "uid"=>$order["uid"],
            "orderId"=>$order["orderId"],
            "payPrice"=>$order["payPrice"],
            "backPrice"=>$backPrice,
            "status"=>2,
            "createtime"=>time(),
            "updatetime"=>time()
        );
        self::insert($data);
        \app\admin\model\rebate\Rebate::saveRebateInfo([
            "uid"=>$order['uid'],
            "orderId"=>$order['orderId'],
            "type"=>9,
            "percent"=>$backPercent,
            "price"=>$backPrice,
            "info"=>'回购商品获得',
        ]);
        Sms::otherSend([
           "uid"=>$order['uid'],
           "type"=>2,
           "payPrice"=>$order["payPrice"],
            "backPrice"=>$backPrice,
        ]);
    }







}
